package com.cooper.controllers.seller;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.cooper.constants.AppConstants;
import com.cooper.constants.ResourceConstants;
import com.cooper.controllers.Controller;
import com.cooper.domain.OrderEntry;
import com.cooper.pagination.PageInfo;
import com.cooper.pagination.PageResult;
import com.cooper.service.core.DictService;
import com.cooper.service.trade.OrderService;
import com.cooper.vo.OrderSearchVo;
import com.google.common.collect.Lists;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.portal.Portal;

public class LogisticsController extends Controller {
	
	@Autowired
	private OrderService orderService;
	
	@Autowired
	private DictService dictService;
	
	@Get @Post
	public String execute(Portal portal, Invocation inv, OrderSearchVo searchVo, PageInfo pageInfo) throws Exception{
		List<String> incompleteStatusList = Lists.newArrayList();
		incompleteStatusList.add(ResourceConstants.TradeStatus.ORDER_CREATED);
		incompleteStatusList.add(ResourceConstants.TradeStatus.ORDER_PAYED);
		if(CollectionUtils.isEmpty(searchVo.getStatusList())){
			searchVo.setStatusList(incompleteStatusList);
		}
		pageInfo.setPageSize(10);
		PageResult<OrderEntry> pageResult = this.orderService.queryForList(searchVo, pageInfo);
		inv.addModel("entryList", pageResult.getResult());
		inv.addModel(AppConstants.pageInfo, pageInfo);
		inv.addModel("searchVo", searchVo);
		inv.addModel("tradeStatusMap", this.dictService.makeOptionList(ResourceConstants.ResourceItem.TRADE_STATUS, null, null));
		return "LogisticsMain";
	}

}
